import moment from "moment";
moment.locale("zh-cn"); //汉化
//vue定义全局过滤器
// type格式默认YYYY-MM-DD HH:mm:ss 其他格式自行传入
let formatDate = (value, type = "YYYY-MM-DD HH:mm:ss", is8 = false) => {
  if (!type) {
    type = "YYYY-MM-DD HH:mm:ss";
  }

  if (!value) {
    return "N/A";
  }
  return moment(value).format(type);
  // if (!is8) {
  //   return moment(value).format(type);
  // } else {
  //   return moment.utc(value).format(type);
  // }
};
// 动态拼接图片文件前缀
const filtersFileUrl = url => {
  // console.log('url :>> ', url);
  if (url) {
    if (url.startsWith("http")) {
      return url;
    } else {
      const isIot = url.startsWith(`/${process.env.VUE_APP_MINIO_bucket}`);
      const newURl = `${process.env.VUE_APP_MINIO_URL}${url}`;
      const newIotURl = `${process.env.VUE_APP_MINIO_URL}/${process.env.VUE_APP_MINIO_bucket}/${url}`;
      url = isIot ? newURl : newIotURl;
      return url;
    }
  } else {
    return "";
  }
};
export { formatDate, filtersFileUrl };
